package org.bright.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.bright.entity.Suppliers;
import org.bright.mapper.SuppliersMapper;
import org.bright.service.ISuppliersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.bright.vo.SuppliersListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bright
 * @since 2024-10-21
 */
@Service
public class SuppliersServiceImpl extends ServiceImpl<SuppliersMapper, Suppliers> implements ISuppliersService {
    @Autowired
    SuppliersMapper suppliersMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param supplierId 主键
     * @return 实例对象
     */
    @Override
    public Suppliers queryById(Integer supplierId) {
        return suppliersMapper.queryById(supplierId);
    }

    /**
     * 分页查询
     *
     * @param suppliers 筛选条件
     * @param pageNum      分页对象
     * @return 查询结果
     */
    @Override
    public PageInfo<Suppliers> queryByPage(Suppliers suppliers, Integer pageNum) {
        PageHelper.startPage(pageNum,5);
        List<Suppliers> list = suppliersMapper.queryAllByLimit(suppliers,pageNum);
        PageInfo<Suppliers> pageInfo =  new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param suppliers 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Suppliers suppliers) {
        return suppliersMapper.insert(suppliers);
    }

    /**
     * 修改数据
     *
     * @param suppliers 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Suppliers suppliers) {
        return suppliersMapper.update(suppliers);
    }

    /**
     * 通过主键删除数据
     *
     * @param supplierId 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer supplierId) {
        return suppliersMapper.deleteById(supplierId);
    }
    @Override
    public List<SuppliersListVO> queryAll() {
        return suppliersMapper.queryAll();
    }
}
